<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<c:if test="${fn:contains(sessionInfo.resourceList, '/myRegister/getSeq')}">
	<script type="text/javascript">
		$.canGet = true;
	</script>
</c:if>
<title>我的挂号</title>
	<script type="text/javascript">
	var dataGrid;
	var patientId = "${patientId}";
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${ctx}' + '/myRegister/dataGrid',
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			idField : 'id',
			sortName : 'id',
			sortOrder : 'asc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
			frozenColumns : [ [ {
				width : '30',
				title : 'id',
				field : 'id',
				sortable : true
			}, {
				width : '130',
				title : '时间段',
				field : 'timeSegment',
				sortable : true
			} ,{
				width : '80',
				title : '挂号医生',
				field : 'doctorName'
			} ,{
				width : '80',
				title : '医生科室',
				field : 'departmentName'
			} ,{
				width : '80',
				title : '挂号方式',
				field : 'type',
				sortable : true,
				formatter : function(value, row, index) {
					switch (value) {
					case 0:
						return '预约挂号';
					case 1:
						return '现场挂号';
					}
				}
			} ,{
				width : '130',
				title : '预约挂号时间',
				field : 'reserveTime'
			} ,{
				width : '130',
				title : '现场取号时间',
				field : 'registerTime'
			} ,{
				width : '50',
				title : '排序号',
				field : 'seq'
			} ,{
				field : 'action',
				title : '操作',
				width : 400,
				formatter : function(value, row, index) {
					var str = '&nbsp;';
					if ($.canGet && row.type==0 && row.seq == undefined) {
						str += $.formatString('<a href="javascript:void(0)" onclick="getSeqFun(\'{0}\');" >取号</a>',row.id);
						str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					}
					str += $.formatString('<a href="javascript:void(0)" onclick="chemicalExamHistory(\'{0}\');" >化验记录</a>', row.timeSegment);
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					str += $.formatString('<a href="javascript:void(0)" onclick="xRayHistory(\'{0}\');" >拍片记录</a>', row.timeSegment);
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					str += $.formatString('<a href="javascript:void(0)" onclick="medicineHistory(\'{0}\');" >开药记录</a>', row.timeSegment);
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					str += $.formatString('<a href="javascript:void(0)" onclick="treatmentHistory(\'{0}\');" >治疗记录</a>', row.timeSegment);
					str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
					return str;
				}
			} ] ],
			toolbar : '#toolbar'
		});
	});
	
	function chemicalExamHistory(timeSegment) {
		parent.$.modalDialog({
			title : '化验历史',
			width : 1000,
			height : 400,
			href : '${ctx}/chargeChemicalExam/historyPage?patientId=' + patientId + "&timeSegment=" + timeSegment
		});
	}
	
	function xRayHistory(timeSegment) {
		parent.$.modalDialog({
			title : '拍片历史',
			width : 1000,
			height : 400,
			href : '${ctx}/chargeXRay/historyPage?patientId=' + patientId + "&timeSegment=" + timeSegment
		});
	}
	
	function medicineHistory(timeSegment) {
		parent.$.modalDialog({
			title : '开药历史',
			width : 1200,
			height : 400,
			href : '${ctx}/registerMedicine/historyPage?patientId=' + patientId + "&timeSegment=" + timeSegment
		});
	}
	
	function treatmentHistory(timeSegment) {
		parent.$.modalDialog({
			title : '治疗历史',
			width : 1000,
			height : 400,
			href : '${ctx}/registerTreatment/historyPage?patientId=' + patientId + "&timeSegment=" + timeSegment
		});
	}
	
	function getSeqFun(id) {
		debugger;
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		
		$.ajax({
			type: "POST",
			async: false,
			data:  {
				'registerId':id,
			},
	        url: '${ctx}/myRegister/getSeq',
	        dataType: "json",
	        success:function(result) {
	        	if(result.status.errorCode == 0) {
	        		$.messager.alert('成功', result.status.errorMsg, 'info',function(r){
	        			dataGrid.datagrid('reload');
	        		});
	        	} else {
	        		$.messager.alert('错误', result.status.errorMsg, 'error');
	        	}
	        },
	        error:function(result) {
	        	debugger;
	        }
   	 	});
	}
	
	</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false">
		<table id="dataGrid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>